<script setup>

import {ref, watch} from "vue";
import {useRoute} from "vue-router";
import {useI18n} from "vue-i18n";

let user = ref({})
let route = useRoute();
let language = ref('');



const i18n = useI18n();
function initLanguage(){
  language.value= i18n.locale.value
}

initLanguage()

function setLanguage(){
  i18n.locale.value=language.value
}


watch(route, () => {
  initLanguage()
}, {immediate: true})

</script>

<template>
  <div id="header">
    <img src="@/assets/png/mark-a-book.png" alt="" class="icon">
    <span>{{ $t('title') }}</span>


    <div class="user">
      <div class="language">
        <el-select size="small" v-model="language" placeholder="Select Language" style="width: 80px" @change="setLanguage">
          <el-option label="中文" value="zh-cn"></el-option>
          <el-option label="English" value="en-us"></el-option>
        </el-select>
      </div>

    </div>

  </div>
</template>

<style scoped>

::v-deep .el-select--small .el-select__wrapper{
  background-color: transparent;
}

::v-deep .el-select__placeholder{
  color: #fff;
}

::v-deep .el-select__placeholder.is-transparent{
  color: #fff;
}

::v-deep .el-select__caret{
  color: #fff;
}

#header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#header span {
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 1px;
}

#header nav {
  transform: translateY(1px);
}

#header nav a .router-link-active {
  color: var(--main-color);
}

#header nav a {
  font-size: 14px;
  letter-spacing: 0.5px;
  color: #f8f8f8;
  transform: translateY(5px);
}

#header nav a:hover {
  font-weight: bold;
}

#header .link {
  margin-left: auto;
  width: 18px;
  height: 18px;
}

#header .link:hover {
  cursor: pointer;
}

#header .link:active {
  opacity: .7;
}

#header .icon{
  width: 32px;
  height: 32px;
}

#header .user{
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
  margin-left: auto;

  .language{
    margin-right: 5px;
  }

  span{
    max-width: 80px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    transition: all 100ms ease-in-out;

    &:hover{
      cursor: pointer;
      transform: translateY(2px);
      opacity: 1;
    }
  }

  .exit{


    &:hover{
      cursor: pointer;
      scale: 1.2;
    }
  }
}

#header .user span:nth-of-type(1){
  opacity: .9;
  font-size: 14px;
}

#header .user span:nth-of-type(2){
  opacity: .8;
  font-size: 10px;
}
</style>
